package com.study.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.study.dto.MyPage;
import com.study.dto.Search;
import com.study.entity.Counties;
import com.study.mapper.CountiesMapper;
import com.study.service.CountiesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lxl
 * @version 2022-06-20 15:41
 */

@Service
public class CountiesServiceImpl implements CountiesService {

    private Logger log = LoggerFactory.getLogger(CountiesServiceImpl.class);

    @Autowired
    private CountiesMapper countiesMapper;

    @Override
    public int deleteByPrimaryKey(Integer countiesId) {
        return countiesMapper.deleteByPrimaryKey(countiesId);
    }

    /**
     * 添加县区记录
     */
    @Override
    public int insert(Counties counties) {
        return countiesMapper.insert(counties);
    }

    @Override
    public int insertSelective(Counties row) {
        return countiesMapper.insertSelective(row);
    }

    @Override
    public Counties selectByPrimaryKey(Integer countiesId) {
        return countiesMapper.selectByPrimaryKey(countiesId);
    }

    @Override
    public int updateByPrimaryKeySelective(Counties row) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Counties row) {
        return countiesMapper.updateByPrimaryKey(row);
    }

    @Override
    public MyPage<Counties> selects(Search search) {
        log.debug("search:{}",JSON.toJSON(search));
        Page<Counties> page = PageHelper.startPage(search.getCurrent(), search.getRowMax(), true)
                .doSelectPage(() -> {
            countiesMapper.selects();
        });
        log.debug("分页信息:{}", JSON.toJSON(page));
        PageInfo<Counties> pageInfo = new PageInfo<>(page);
        return new MyPage<Counties>().init(pageInfo);
    }

    @Override
    public List<Counties> dimByName(String countiesName) {
        return countiesMapper.dimByName(countiesName);
    }

    @Override
    public List<Counties> selectAll() {
        return countiesMapper.selects();
    }


}
